
/*

Dofile: table4.do 

Date: Dec. 10, 2016 
Aim: Quantify under-reporting to tax havens  

Input: base_for_reg.dta 
Output: table4.dta 
Reported in the paper: "Table 4: Under-reporting to tax havens"

*/  

cd $datapath
use base_for_reg, clear 


global condition 
global tax_var interdum_hines dum_hines
areg luv type $tax_var inter_tarif tarif inter_lgdpc lgdpc inter_ldist ldist $condition, absorb(fpt) cluster(pays)
preserve 
g coef_dumth=_b[interdum_hines]
g se_dumth_pays=_se[interdum_hines]
g coef_tarif=_b[inter_tarif]
g se_tarif=_se[inter_tarif]
egen prod_mode=group(nc8)
areg luv type $tax_var inter_tarif tarif inter_lgdpc lgdpc inter_ldist ldist $condition, absorb(fpt) cluster(prod_mode)
g se_dumth_prod=_se[interdum_hines]
keep if dum_hines==1
keep iso3 coef_* se_*
duplicates drop coef_dumth iso3, force
sort iso3
save coef_th, replace 

use base_dmpt, replace 
drop if export==0 | export==.
g test=1 - exporths4/export_mondia 
sum test, d 
drop if test!=. & abs(test)>0.01

collapse (sum) export (mean) export_mondia, by(siren iso3 hs4) 
collapse (sum) export export_mondia, by(iso3) 
sort iso3 
merge m:1 iso3 using coef_th
egen tot=sum(export) 
g shc=export/tot 
g shi=export_mondia/export 
g loss=(exp(coef_dumth)-1)*export_mondia 
g loss_min=(exp(coef_dumth - 1.64*se_dumth_pays)-1)*export_mondia 
g loss_max=(exp(coef_dumth + 1.64*se_dumth_pays)-1)*export_mondia 

g loss_min_alt=(exp(coef_dumth - 1.64*se_dumth_prod)-1)*export_mondia 
g loss_max_alt=(exp(coef_dumth + 1.64*se_dumth_prod)-1)*export_mondia 


egen t=sum(loss) 
g loss_tax=0.318*t

gsort - export_mondia 
br iso3 shc shi loss* if loss!=.
save $resultpath/table4.dta, replace 
